#include "PlayThread.h"
#include <iostream>

using namespace std;

PlayThread::PlayThread(QObject *parent) : QThread(parent) {
    running_flag = false;
    dtimes = NULL;
}

void PlayThread::run()
{
    running_flag = true;
    int count=0;
    int timeNow=0;
    int waitForIt=0;
    while(1) {
        istheEnd.lock();
        if(!running_flag) {
            cout << "Stopped PlayThread" << endl;
            istheEnd.unlock();
            break;
        }
        istheEnd.unlock();

        emit show_now();

        timeNow = timer.restart();
        waitForIt = dtimes->at(count+1);
        cout << "printing " << count << " Next in " << dtimes->at(count+1) << " ms || Time now: " << timeNow << endl;
        msleep(waitForIt);

        count++;

    }
}

void PlayThread::stop()  {
    istheEnd.lock();
    running_flag = false;
    istheEnd.unlock();
}

void PlayThread::setDtime(vector<int> dtimes)
{
    this->dtimes = new vector<int>(dtimes);
}
